#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QQuickView>
#include "./CanLib/ControlCAN.h"
#include "canthread.h"
#include "qcustomplot.h"
#include <QThread>
#include <QSerialPort>
#include <QLabel>
#include <QtSerialPort/QSerialPort>         // 提供访问串口的功能
#include <QtSerialPort/QSerialPortInfo>     // 提供系统中存在的串口信息
//#include <QtDeclarative/QDeclarativeView>

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

    void View_init();
    void progressInit();
    void CANConnect();
    void Customplot();

    void DCDC1Sstate1(QString da);
    void DCDC1Sstate2(QString da);

    void TemBug1(QString da);

    void timerEvent(QTimerEvent *event);

    void createIndicatorLabel(QLabel* label, int color, int size, QString number, bool numlock);
    void createIndicatorLabel1(QLabel* label, int color, int size, QString number, bool numlock);

    QThread thread1;

    QThread *thread2 = NULL;
    canThread *can = NULL;

    QString s0 = "00000";
    QString s1 = "00";
    QString s2 = "0";
    QString daV = "0000";
    QString daA = "00";
    QString daW = "00";
    QString daZK = "00";
    QString daZKBlimit = "00";

/************** 温度数据 ***************/
    float Tem1_1;
    float Tem1_2;
    float Tem1_3;
    float Tem1_4;
    float Tem1_5;
    float Tem1_6;

    float Tem2_1;
    float Tem2_2;
    float Tem2_3;
    float Tem2_4;
    float Tem2_5;
    float Tem2_6;

    float Tem3_1;
    float Tem3_2;
    float Tem3_3;
    float Tem3_4;
    float Tem3_5;
    float Tem3_6;

/************** 电压电流、温度数据 ***************/
    int DC1_inV = 0;
    int DC1_inA = 0;
    int DC1_putV = 0;
    int DC1_putA = 0;
    int ZLQ1_inV = 0;
    int ZLQ1_inA = 0;
    int SQ1Tem = 0;
    int XQ1Tem = 0;
    int DG1Tem = 0;

    int DC2_inV = 0;
    int DC2_inA = 0;
    int DC2_putV = 0;
    int DC2_putA = 0;
    int ZLQ2_inV = 0;
    int ZLQ2_inA = 0;
    int SQ2Tem = 0;
    int XQ2Tem = 0;
    int DG2Tem = 0;

    int DC3_inV = 0;
    int DC3_inA = 0;
    int DC3_putV = 0;
    int DC3_putA = 0;
    int ZLQ3_inV = 0;
    int ZLQ3_inA = 0;
    int SQ3Tem = 0;
    int XQ3Tem = 0;
    int DG3Tem = 0;

/******************************* 温度故障警告判断 ********************************/
    QString bug1_1 = "0";
    QString bug1_2 = "0";
    QString bug1_3 = "0";
    QString bug1_4 = "0";
    QString bug1_5 = "0";
    QString bug1_6 = "0";
    QString bug1_7 = "0";

    QString bug2_1 = "00";
    QString bug2_2 = "00";
    QString bug2_3 = "00";
    QString bug2_4 = "00";
    QString bug2_5 = "00";
    QString bug2_6 = "00";

    QString bug3_1 = "00";
    QString bug3_2 = "00";
    QString bug3_3 = "00";
    QString bug3_4 = "00";
    QString bug3_5 = "00";
    QString bug3_6 = "00";

private slots:
    void on_btnCAN_clicked();//打开CAN

    void Sendflag_off();

    void on_pushButton_clicked();

    void on_pushButton_2_clicked();

    //游标函数
    void mouseMoveEvent(QMouseEvent *event);

    //图例选中曲线函数
    void selectionChanged();


    void on_comboBox_activated(int index);

signals:
    void SIGtocansen(unsigned int ID, std::vector<int> vec);
    void SIGtocancon();                                     //启动CAN按钮发出的信号
    void SIGtocansto();                                     //关闭CAN按钮发出的信号

    void SIG_bug1(QString da);
    void SIG_bug2(QString da);
    void SIG_bug3(QString da);

    void SIGBUGFlagOff();
    void SIGBUGFlag();
    void SIGBUGTem1();
    void SIGBUGTem2();
    void SIGWarnTem1();
    void SIGWarnTem2();

private:
    Ui::MainWindow *ui;

    QTimer m_timer;//485定时器1
    QTimer m_timer1;//485定时器2
    QTimer m_timer2;//485定时器3
    QTimer tem_timer;//获取温度值定时器1
    QTimer tem_timer1;//获取温度值定时器2
    QTimer tem_timer2;//获取温度值定时器3

    QSerialPort SerialPort;//串口号1
    QSerialPort SerialPort1;//串口号2
    QSerialPort SerialPort2;//串口号3

    QCustomPlot *plot;
    QCPItemTracer *tracer;  //游标定义

    int refreshTimer; //刷新图像的定时器
    int sampleTimer; //模拟采样的定时器

};
#endif // MAINWINDOW_H
